<?php

if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

/**
*
* @package  RealEstateManager
* @copyright 2011 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
* Homepage: http://www.ordasoft.com
* @version: 2.1 free $

*
**/

include_once( dirname(__FILE__).'/compat.joomla1.5.php' );
require_once ($mosConfig_absolute_path."/components/com_realestatemanager/realestatemanager.class.php");

if(!defined( '_JLEGACY' ))
{
 $GLOBALS['path'] = $mosConfig_live_site."/components/com_realestatemanager/images/";
}
else 
{
$GLOBALS['path'] = $mosConfig_live_site."/administrator/components/com_realestatemanager/images/";
}
$path = $GLOBALS['path'];
class DMInstallHelper
{ 
function getComponentId()
    {
          global $database;
          $database->setQuery("SELECT extension_id FROM #__extensions WHERE `element`='com_realestatemanager' ");
          $id =$database->loadResult();
          return $id;
    }

function getParentId()
    {
        $id = DMInstallHelper::getComponentId();
        
        global $database;
        $database->setQuery("SELECT id FROM #__menu WHERE title='RealEstate Manager' and level=1 and parent_id=1 and component_id=$id" );
        $parent_id =$database->loadResult();
      
        return $parent_id;
    }

   
    function setAdminMenuImages(){
      global $database,$path;

        $id = DMInstallHelper::getComponentId();
        $parent_id = DMInstallHelper::getParentId();
        // Main mennu
        $database->setQuery("UPDATE #__menu SET img = 'class:dm_component.png' WHERE title='RealEstate Manager' and level=1 and parent_id=1 and component_id=$id");
        $database->query();

        // Submenus
        $submenus = array();
        $submenus[] = array( 'img' => 'class:module', 'title'=>'Houses' );
        $submenus[] = array( 'img' => 'class:dm_credits', 'title'=>'Categories' );
        $submenus[] = array( 'img' => 'class:move', 'title'=>'Rent Requests' );
        $submenus[] = array( 'img' => 'class:config', 'title'=>'Settings Frontend' );
        $submenus[] = array( 'img' => 'class:config', 'title'=>'Settings Backend' );
        $submenus[] = array( 'img' => 'class:info', 'title'=>'About' );
       

        foreach( $submenus as $submenu )
        {
          $database->setQuery("UPDATE #__menu img = '".$submenu['img']."'".
            "\n WHERE  component_id=$id AND  parent_id = '".$parent_id." and level=2  AND title = '".$submenu['title']."';");
          $database->query();

        }
    }
}

